import Setting from "~/utils/setting";

import { message } from "ant-design-vue";
export default function ({ $axios, redirect, app }) {
    /**
     * 错误
     */
    $axios.onError(error => {
        console.log(error, '错误');
        message.error("请求错误");
        return redirect({
            name: "index",
        });
    })
    /**
     * 请求拦截
     */
    $axios.onRequest(config => {
        // console.log(config,'请求拦截');
        config.headers = {
            "Accept-Language": Setting.language,
            // "Authorization": 'Bearer ' + app.$cookies.get('token'),
            "token": app.$cookies.get('token'),
        }
    })
    /**
     * 响应拦截
     */
    $axios.onResponse(response => {
        // console.log(response,'响应拦截');
    })
    // Adds header: `Authorization: 123` to all requests -- https://axios.nuxtjs.org/helpers
    // this.$axios.setHeader('Authorization', '123')
    // Adds header: `Authorization: 123` to all requests
    // this.$axios.setToken('123')

    /**
     * 请求错误
     */
    // $axios.onRequestError(err=>{
    //     console.log(err,'请求错误');
    // })
    /**
     * 响应错误
     */
    // $axios.onResponseError(err=>{
    //     console.log(err,'响应错误');
    // })
}
